package org.example.model.vo;

import lombok.Data;
import org.example.constants.BusiRspEnum;
import org.example.constants.RspEnum;
import org.example.exception.RspException;

import java.io.Serializable;

/**
 * @author jingjing.zhang
 */
@Data
public class Response<T> implements Serializable {
    private static final long serialVersionUID = 9136629148939279769L;

    private String appName;
    private String rspCode;
    private String rspMsg;
    private String busiCode;
    private String busiMsg;
    /** 总记录数 */
    private Integer totalRecords;
    /** 总页数 */
    private Integer totalPages;
    /** 当前页 */
    private Integer currentPage;
    /** 每页记录数 */
    private Integer pageSize;

    /** 请求时间 */
    private String timestamp;
    private T data;

    public Response() {
    }

    private Response(String rspCode,String rspMsg,String busiCode,String busiMsg,T t){
        this.rspCode = rspCode;
        this.rspMsg = rspMsg;
        this.busiCode = busiCode;
        this.busiMsg = busiMsg;
        this.data = t;
    }

    public Response(RspEnum rspEnum) {
        this.rspCode = rspEnum.getCode();
        this.rspMsg = rspEnum.getMsg();
    }

    public Response(RspException rspException) {
        this.rspCode = rspException.getCode();
        this.rspMsg = rspException.getMsg();
    }

    public Response(BusiRspEnum busiRspEnum, T t) {
        this(RspEnum.SUCCESS.getCode(),RspEnum.SUCCESS.getMsg(),busiRspEnum.getCode(),busiRspEnum.getMsg(),t);
    }
}
